package org.stragma.apply.signatures

import org.stragma.apply.signatures.Apply._

object Options {

    import aterm._
    import aterm.pure.SingletonFactory
    import scala.collection.mutable.ListBuffer

    case class Evaluate_constant_expressions () extends TExp
    case class Propagate_constant_assignments () extends TExp
    case class Normalise_expressions () extends TExp
    case class Generate_if_assertions () extends TExp
    case class Generate_loop_assertions () extends TExp
    case class Use_program_assertions () extends TExp
    case class Use_apply_assertions () extends TExp
    case class Merge_complex_multiply () extends TExp
    case class No_evaluate_constant_expressions () extends TExp
    case class No_propagate_constant_assignments () extends TExp
    case class No_normalise_expressions () extends TExp
    case class No_generate_if_assertions () extends TExp
    case class No_generate_loop_assertions () extends TExp
    case class No_use_program_assertions () extends TExp
    case class No_use_apply_assertions () extends TExp
    case class Optimise_2 () extends TExp
    case class Optimise_1 () extends TExp
    case class Optimise_0 () extends TExp
    case class Simple () extends TExp
    case class Test () extends TExp
    case class Loop_1 () extends TExp
    case class Loop_2 () extends TExp
    case class Loop_10 () extends TExp
    case class Loop_block () extends TExp
    case class Loop_raster () extends TExp
    case class Loop_index () extends TExp
    case class Loop_noindex () extends TExp
    case class Loop_nosingle () extends TExp
    case class Width_512 () extends TExp

    def ATermToTExp (term : ATerm) : TExp =
        term match {
            case t : ATermAppl =>
                val args = t.getArgumentArray ()
                t.getName match {
                    case "Loop_noindex" if (args.length == 0) => 
                        Loop_noindex ()
                    case "Merge_complex_multiply" if (args.length == 0) => 
                        Merge_complex_multiply ()
                    case "Optimise_1" if (args.length == 0) => 
                        Optimise_1 ()
                    case "Loop_raster" if (args.length == 0) => 
                        Loop_raster ()
                    case "Generate_if_assertions" if (args.length == 0) => 
                        Generate_if_assertions ()
                    case "Generate_loop_assertions" if (args.length == 0) => 
                        Generate_loop_assertions ()
                    case "Evaluate_constant_expressions" if (args.length == 0) => 
                        Evaluate_constant_expressions ()
                    case "Loop_10" if (args.length == 0) => 
                        Loop_10 ()
                    case "Normalise_expressions" if (args.length == 0) => 
                        Normalise_expressions ()
                    case "Loop_1" if (args.length == 0) => 
                        Loop_1 ()
                    case "Test" if (args.length == 0) => 
                        Test ()
                    case "No_evaluate_constant_expressions" if (args.length == 0) => 
                        No_evaluate_constant_expressions ()
                    case "Loop_index" if (args.length == 0) => 
                        Loop_index ()
                    case "No_propagate_constant_assignments" if (args.length == 0) => 
                        No_propagate_constant_assignments ()
                    case "No_generate_if_assertions" if (args.length == 0) => 
                        No_generate_if_assertions ()
                    case "Loop_block" if (args.length == 0) => 
                        Loop_block ()
                    case "No_use_apply_assertions" if (args.length == 0) => 
                        No_use_apply_assertions ()
                    case "Simple" if (args.length == 0) => 
                        Simple ()
                    case "Optimise_2" if (args.length == 0) => 
                        Optimise_2 ()
                    case "Optimise_0" if (args.length == 0) => 
                        Optimise_0 ()
                    case "Propagate_constant_assignments" if (args.length == 0) => 
                        Propagate_constant_assignments ()
                    case "Use_program_assertions" if (args.length == 0) => 
                        Use_program_assertions ()
                    case "Width_512" if (args.length == 0) => 
                        Width_512 ()
                    case "No_generate_loop_assertions" if (args.length == 0) => 
                        No_generate_loop_assertions ()
                    case "No_normalise_expressions" if (args.length == 0) => 
                        No_normalise_expressions ()
                    case "No_use_program_assertions" if (args.length == 0) => 
                        No_use_program_assertions ()
                    case "Loop_2" if (args.length == 0) => 
                        Loop_2 ()
                    case "Use_apply_assertions" if (args.length == 0) => 
                        Use_apply_assertions ()
                    case "Loop_nosingle" if (args.length == 0) => 
                        Loop_nosingle ()
                    case n =>
                        sys.error ("unknown constructor " + n + " for TExp found")
                }
            case _ =>
                sys.error ("non-application aterm found for TExp: " + term)
        }

    def ATermToString (term : ATerm) : String =
        term match {
            case t : ATermAppl =>
                t.getName
            case _ =>
                sys.error ("ATermAppl expected in atermToString but " + term + " found")
        }

    private val f = SingletonFactory.getInstance ()

    def TExpToATerm (value : TExp) : ATerm =
        value match {
            case v : Loop_noindex =>
                val fun = f.makeAFun ("Loop_noindex", 0, false)
                f.makeAppl (fun)
            case v : Merge_complex_multiply =>
                val fun = f.makeAFun ("Merge_complex_multiply", 0, false)
                f.makeAppl (fun)
            case v : Optimise_1 =>
                val fun = f.makeAFun ("Optimise_1", 0, false)
                f.makeAppl (fun)
            case v : Loop_raster =>
                val fun = f.makeAFun ("Loop_raster", 0, false)
                f.makeAppl (fun)
            case v : Generate_if_assertions =>
                val fun = f.makeAFun ("Generate_if_assertions", 0, false)
                f.makeAppl (fun)
            case v : Generate_loop_assertions =>
                val fun = f.makeAFun ("Generate_loop_assertions", 0, false)
                f.makeAppl (fun)
            case v : Evaluate_constant_expressions =>
                val fun = f.makeAFun ("Evaluate_constant_expressions", 0, false)
                f.makeAppl (fun)
            case v : Loop_10 =>
                val fun = f.makeAFun ("Loop_10", 0, false)
                f.makeAppl (fun)
            case v : Normalise_expressions =>
                val fun = f.makeAFun ("Normalise_expressions", 0, false)
                f.makeAppl (fun)
            case v : Loop_1 =>
                val fun = f.makeAFun ("Loop_1", 0, false)
                f.makeAppl (fun)
            case v : Test =>
                val fun = f.makeAFun ("Test", 0, false)
                f.makeAppl (fun)
            case v : No_evaluate_constant_expressions =>
                val fun = f.makeAFun ("No_evaluate_constant_expressions", 0, false)
                f.makeAppl (fun)
            case v : Loop_index =>
                val fun = f.makeAFun ("Loop_index", 0, false)
                f.makeAppl (fun)
            case v : No_propagate_constant_assignments =>
                val fun = f.makeAFun ("No_propagate_constant_assignments", 0, false)
                f.makeAppl (fun)
            case v : No_generate_if_assertions =>
                val fun = f.makeAFun ("No_generate_if_assertions", 0, false)
                f.makeAppl (fun)
            case v : Loop_block =>
                val fun = f.makeAFun ("Loop_block", 0, false)
                f.makeAppl (fun)
            case v : No_use_apply_assertions =>
                val fun = f.makeAFun ("No_use_apply_assertions", 0, false)
                f.makeAppl (fun)
            case v : Simple =>
                val fun = f.makeAFun ("Simple", 0, false)
                f.makeAppl (fun)
            case v : Optimise_2 =>
                val fun = f.makeAFun ("Optimise_2", 0, false)
                f.makeAppl (fun)
            case v : Optimise_0 =>
                val fun = f.makeAFun ("Optimise_0", 0, false)
                f.makeAppl (fun)
            case v : Propagate_constant_assignments =>
                val fun = f.makeAFun ("Propagate_constant_assignments", 0, false)
                f.makeAppl (fun)
            case v : Use_program_assertions =>
                val fun = f.makeAFun ("Use_program_assertions", 0, false)
                f.makeAppl (fun)
            case v : Width_512 =>
                val fun = f.makeAFun ("Width_512", 0, false)
                f.makeAppl (fun)
            case v : No_generate_loop_assertions =>
                val fun = f.makeAFun ("No_generate_loop_assertions", 0, false)
                f.makeAppl (fun)
            case v : No_normalise_expressions =>
                val fun = f.makeAFun ("No_normalise_expressions", 0, false)
                f.makeAppl (fun)
            case v : No_use_program_assertions =>
                val fun = f.makeAFun ("No_use_program_assertions", 0, false)
                f.makeAppl (fun)
            case v : Loop_2 =>
                val fun = f.makeAFun ("Loop_2", 0, false)
                f.makeAppl (fun)
            case v : Use_apply_assertions =>
                val fun = f.makeAFun ("Use_apply_assertions", 0, false)
                f.makeAppl (fun)
            case v : Loop_nosingle =>
                val fun = f.makeAFun ("Loop_nosingle", 0, false)
                f.makeAppl (fun)
            case _ =>
                sys.error ("unexpected value found for TExp: " + value)
        }

    def StringToATerm (value : String) : ATerm =
        f.makeAppl (f.makeAFun (value, 0, true)) 

}